package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CustomerTraceHistory;
import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ICustomerTraceHistoryService;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import cn.wolfcode.crm.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/customerTraceHistory")
public class CustomerTraceHistoryController {
    @Autowired
    private ICustomerTraceHistoryService traceHistoryService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;
    @RequestMapping("/list")
    public String potentialList(Model model, @ModelAttribute("qo") QueryObject qo){

        //通过字典目录和明细查询客户跟进方式,共享到页面
        List<SystemDictionaryItem> ccts = systemDictionaryItemService.selectBySystemDictionaryCommunicationMethod();
        model.addAttribute("ccts",ccts);

        PageInfo pageInfo = traceHistoryService.query(qo);
        model.addAttribute("result",pageInfo);
        return "/customerTraceHistory/list";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(CustomerTraceHistory customerTraceHistory){
        if(customerTraceHistory.getId() != null){
            traceHistoryService.update(customerTraceHistory);
        }else {
            traceHistoryService.save(customerTraceHistory);
        }
        return new JsonResult();
    }

}
